<?php

class Ext_Graphics
{
    private $_adapter;
    
    protected static $_instance = null;

    public static function getInstance()
    {
        if (null === self::$_instance) {
            self::$_instance = new self();
        }

        return self::$_instance;
    }
    
    public function __construct()
    {
        if(!isset($this->_adapter))
        {
            $_config = Ext_Config::getInstance()->getConfig('image');
            
            $classname = "Ext_Graphics_Adapter_".ucfirst($_config->graphics->adapter);
            if(!class_exists( $classname ))
            {
                    require_once 'Ext/Graphics/Exception.php';
                    throw new Ext_Graphics_Exception("Graphics adapter '".$classname."' is not exists.");
            }

            $this->_adapter = new $classname();
        }
    }
    
    public function getAdapter()
    {
        $_adapter = $this->_adapter;
        return $_adapter;
    }
    
    public function setSourceFile($file)
    {
        $this->_adapter->setSourceFile($file);
    }
    
    public function resize($newFile, $newWidth, $newHeight) 
    {
        $this->_adapter->resize($newFile, $newWidth, $newHeight);        
    }
}

?>
